#include "Util.h"

namespace great_config {

	string Util::trim(const string &str) {
		size_t from = 0, to = str.size() - 1;
		while(str[from] == ' ' || str[from] == '\t' || str[from] == '\n' || str[from] == '\r') {
			from ++;
		}
		while(str[to] == ' ' || str[to] == '\t' || str[to] == '\n' || str[to] == '\r') {
			to --;
		}
		return str.substr(from, to - from + 1);
	}

	vector<string> &Util::split(const string &str, vector<string> &vec, const char delim) {
		size_t prepos = 0,
			   pos = str.find(delim);
		vec.clear();

		while(pos != string::npos) {
			vec.push_back(str.substr(prepos, pos - prepos));		
			prepos = pos + 1;

			pos = str.find(delim, prepos);
		}

		vec.push_back(str.substr(prepos, min(pos, str.size()) - prepos));
		return vec;
	}

}
